public class Solution {
    public static void main(String[] args) {
        Solution1 abc = new Solution1();
        String abcd = abc.addBinary("11", "1");
        System.out.println("结果"+Integer.parseInt(abcd));
    }
    static class Solution1 {
        public String addBinary(String a, String b) {
            StringBuilder ans = new StringBuilder();    //ans=""
            int ca = 0;     //0  1
            for (int i = a.length() - 1, j = b.length() - 1; i >= 0 || j >= 0; i--, j--) {  //  i=1 j=0     i=0 j=-1
                int sum = ca;   // 0    1
                //三则运算
                // sum += i >= 0 ? a.charAt(i) - '0' : 0;
                //首先判断下 i >= 0  return  a.charAt(i) - '0'       false 0     然后再 sum += i
                //a.charAt(i) - '0'    就是1-0=1
                //i >= 0 ?    1>0
                //sum += 求和
                sum += i >= 0 ? a.charAt(i) - '0' : 0;  //i=1 a=11  i=0 a=11
                sum += j >= 0 ? b.charAt(j) - '0' : 0;  //j=0 b=1   j=-1 b=1
                //append 拼接
                ans.append(sum % 2);    //ans=""    sum="2"     0   00
                ca = sum / 2;   //1
            }
            ans.append(ca == 1 ? ca : "");
            //reverse表示反转
            return ans.reverse().toString();    //001
        }
    }
}
